package com.itboye.ihomebank.base;

import android.app.Activity;
import android.app.Application;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;

import com.itboye.ihomebank.util.broad.BroadEnum;

/**
 * Created by Administrator on 2018/3/5 0005.
 */

public class AppLifeCycle implements Application.ActivityLifecycleCallbacks {

    private int activityAount = 0;
    private boolean isAppForeground = true;
    private Activity activity_old=null;
    @Override
    public void onActivityCreated(Activity activity, Bundle savedInstanceState) {

    }

    @Override
    public void onActivityStarted(Activity activity) {



  }

    @Override
    public void onActivityResumed(Activity activity) {
//        Log.d("activity====",activity.getLocalClassName()+"");
        MyApplcation.MyActivityManager.getInstance().setCurrentActivity(activity);
        if (activity_old==null){
            activity_old=activity;
        }else {
            if (activity_old!=activity){
                activity_old=activity;
            }else {
                Log.d("activity====",activity.getLocalClassName()+"");
                // 发送广播到baseactivity 弹出相应弹框
//                Intent intent = new Intent(BroadEnum.APP_START_TanKuang);
                MyApplcation.curActivity=activity;
                MyApplcation.ctx.sendBroadcast(new Intent(BroadEnum.APP_START_TanKuang));
            }
        }

        //加载完第一个activity后


    }

    @Override
    public void onActivityPaused(Activity activity) {

    }

    @Override
    public void onActivityStopped(Activity activity) {
         activityAount--;
        if (activityAount == 0 ) {
            // 此时表明应用在后台
            isAppForeground = false;
            // do something by yourself
            // Intent i = new Intent(MyApplication.getMyApplication(), TrackService.class);
            // MyApplication.getMyApplication().startService(i);
        }
    }

    @Override
    public void onActivitySaveInstanceState(Activity activity, Bundle outState) {

    }

    @Override
    public void onActivityDestroyed(Activity activity) {

    }
}
